﻿using System.Text.Json.Serialization;
using Simple.Common.Helpers;

namespace Simple.Services;

public class CourseModel : ModelBase
{
    /// <summary>
    /// 主键
    /// </summary>
    public Guid? Id { get; set; }

    /// <summary>
    /// 课程名称
    /// </summary>
    public string? CourseName { get; set; }

    /// <summary>
    /// 课程分类Id
    /// </summary>
    public Guid? CourseTypeId { get; set; }
    /// <summary>
    /// 课程分类
    /// </summary>
    public string? CourseTypeStr { get; set; }

    /// <summary>
    /// 讲师id
    /// </summary>
    public Guid? LecturerId { get; set; }
    /// <summary>
    /// 讲师名
    /// </summary>
    public string? LecturerName { get; set; }

    /// <summary>
    /// 课程分类
    /// </summary>
    public virtual CourseType? CourseType { get; set; }

    /// <summary>
    /// 讲师
    /// </summary>
    public virtual Lecturer? Lecturer { get; set; }

    /// <summary>
    /// 课程来源
    /// </summary>
    public EnumCourseSource Coursesource { get; set; }
    /// <summary>
    /// 课程来源
    /// </summary>
    public string? CoursesourceStr { get; set; }

    /// <summary>
    /// 时长（分钟）
    /// </summary>
    public double Duration { get; set; }

    /// <summary>
    /// 图片id
    /// </summary>
    public string? ImgId { get; set; }

    /// <summary>
    /// 视频id
    /// </summary>
    public string? VideosId { get; set; }

    /// <summary>
    /// 视频链接
    /// </summary>
    public string? VideosLink { get; set; }

    /// <summary>
    /// 是否启用
    /// true--启用
    /// </summary>
    public bool IsEnable { get; set; }

    /// <summary>
    /// 介绍
    /// </summary>
    public string? Description { get; set; }

    /// <summary>
    /// 点播次数
    /// </summary>
    public int? PlayCount { get; set; } = 0;


    public override void ConfigureMapper(Profile profile)
    {
        profile.CreateMap<Course, CourseModel>()
            .ForMember(d => d.Coursesource, options => options.MapFrom(s => (int)s.Coursesource))
            .ForMember(d => d.CoursesourceStr, options => options.MapFrom(s => EnumHelper.GetDescriptionContent(s.Coursesource)))
            .ForMember(d => d.CourseTypeStr, options => options.MapFrom(s => s.CourseType == null ? string.Empty : s.CourseType.Name))
            .ForMember(d => d.LecturerName, options => options.MapFrom(s => s.Lecturer == null ? string.Empty : s.Lecturer.Name))
        .ForMember(d => d.PlayCount, options => options.MapFrom(s => s.PlayCount.HasValue ? s.PlayCount : 0));

        profile.CreateMap<CourseModel, Course>();

    }

}
